import { Module } from '@nestjs/common';
import { TypeOrmModule, TypeOrmModuleOptions } from '@nestjs/typeorm';
import { Area } from './entity/area.entity';
import { AssetsType } from './entity/assets-type.entity';
import { Assets } from './entity/assets.entity';
import { Feedback } from './entity/feedback.entity';
import { Funds } from './entity/funds.entity';
import { Group } from './entity/group.entity';
import { LearningResources } from './entity/learning-resources.entity';
import { Logger } from './entity/logger.entity';
import { Migrate } from './entity/migrate.entity';
import { NonOperatingAssets } from './entity/non-operating-assets.entity';
import { OperatingAssets } from './entity/operating-assets.entity';
import { OrgActionType } from './entity/org-action-type.entity';
import { OrgAction } from './entity/org-action.entity';
import { PartyMember } from './entity/party-member.entity';
import { Photo } from './entity/photo.entity';
import { PhotoMetadata } from './entity/photoMetadata.entity';
import { ProjectConstruction } from './entity/project-construction.entity';
import { ResourcesType } from './entity/resources-type.entity';
import { Resources } from './entity/resources.entity';
import { SubsidyInfo } from './entity/subsidy-info.entity';
import { SubsidyType } from './entity/subsidy-type.entity';
import { Subsidy } from './entity/subsidy.entity';
import { Town } from './entity/town.entity';
import { User } from './entity/user.entity';
import { VillageActionType } from './entity/village-action-type.entity';
import { VillageAction } from './entity/village-action.entity';
import { VillageBulletinBoard } from './entity/village-bulletin-board.entity';
import { VillageCadre } from './entity/village-cadre.entity';
import { VillageMeeting } from './entity/village-meeting.entity';
import { Village } from './entity/village.entity';
import { Villager } from './entity/villager.entity';


const entities = [
  Area,
  Assets,
  AssetsType,
  Feedback,
  Funds,
  Group,
  LearningResources,
  Migrate,
  NonOperatingAssets,
  OperatingAssets,
  OrgAction,
  OrgActionType,
  PartyMember,
  Photo,
  PhotoMetadata,
  ProjectConstruction,
  Resources,
  ResourcesType,
  Subsidy,
  SubsidyInfo,
  SubsidyType,
  Town,
  User,
  Village,
  VillageAction,
  VillageActionType,
  VillageBulletinBoard,
  VillageCadre,
  VillageMeeting,
  Villager,
  Logger
]

@Module({
  imports: [
    
    // TypeOrmModule.forRootAsync({
    //   useFactory() {
    //     return {
    //       "name": "animalsConnection",
    //       "type": process.env.DB_TYPE_MYSQL_LOGGER,
    //       "host": process.env.DB_HOST_MYSQL_LOGGER,
    //       "port": process.env.DB_PORT_MYSQL_LOGGER,
    //       "username": process.env.DB_USERNAME_MYSQL_LOGGER,
    //       "password": process.env.DB_PASSWORD_MYSQL_LOGGER,
    //       "database": process.env.DB_DATABASE_MYSQL_LOGGER,
    //       "entities": [Logger],
    //       "synchronize": true,
    //       "logger": "advanced-console",
    //       "logging": true,
    //       maxQueryExecutionTime: 100
    //     } as TypeOrmModuleOptions
    //   }
    // }),
    // TypeOrmModule.forRoot({
    //   type: 'mysql',
    //   // name: 'Logger', // pay attention to the connection name
    //   host:  'localhost', 
    //   port: 3306,
    //   username: 'root',
    //   password: 'root',
    //   database: 'Logger',
    //   entities: [ ...entities, Logger ],
    //   synchronize: true,
    //   logger: "advanced-console",
    //   logging: true,
    //   maxQueryExecutionTime: 100
    // }),
    TypeOrmModule.forRootAsync({
      useFactory() {
            return {
              "type": process.env.DB_TYPE_MYSQL,
              "host": process.env.DB_HOST_MYSQL,
              "port": process.env.DB_PORT_MYSQL,
              "username": process.env.DB_USERNAME_MYSQL,
              "password": process.env.DB_PASSWORD_MYSQL,
              "database": process.env.DB_DATABASE_MYSQL,
              "entities": [...entities, Logger],
              "synchronize": false,
              "logger": "advanced-console",
              "logging": ["error", "warn"],
              maxQueryExecutionTime: 100
            } as TypeOrmModuleOptions
          }
    }),
    // TypeOrmModule.forRootAsync({
    //   useFactory() {
    //     return {
    //       "type": process.env.DB_TYPE_MYSQL_LOGGER,
    //       "host": process.env.DB_HOST_MYSQL_LOGGER,
    //       "port": process.env.DB_PORT_MYSQL_LOGGER,
    //       "username": process.env.DB_USERNAME_MYSQL_LOGGER,
    //       "password": process.env.DB_PASSWORD_MYSQL_LOGGER,
    //       "database": process.env.DB_DATABASE_MYSQL_LOGGER,
    //       "entities": entities,
    //       "synchronize": false,
    //       "logger": "advanced-console",
    //       "logging": true,
    //       maxQueryExecutionTime: 100
    //     } as TypeOrmModuleOptions
    //   }
    // }),
    // TypeOrmModule.forFeature([Logger], "Logger")
  ],
})
export class DbModule {}
